package com.itany.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.mapper.PermissionMapper;
import com.itany.pojo.Permission;
import com.itany.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author：侍家宇
 * Date：2019-09-25 下午6:24
 * Description：<描述>
 */
@Service
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRED)
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    /**
     * 页面展示查询
     * @param page
     * @param rows
     * @return
     */
    public PageInfo<Permission> findAllPermission(Integer page, Integer rows) {
        PageHelper.startPage(page,rows);
        List<Permission> list = permissionMapper.findAllPermission();
        PageInfo<Permission> info = new PageInfo<Permission>(list);

            // if(info.getList().size() !=0){
            //     for(Permission p:info.getList()){
            //         Permission permission=permissionMapper.selectById(p.getParentid());
            //         p.
            //     }
            // }

        return info;


    }

    /**
     * 修改前查询
     * @param id
     * @return
     */
    public Permission findpermission(Integer id) {
        Permission permission=permissionMapper.findpermission(id);
        return permission;
    }

    /**
     * 修改
     * @param permission
     */
    public void modifyPermission(Permission permission) {
        permissionMapper.modifyPermission(permission);
    }
}
